'use strict';
var hp = require("./zunyi_hupai");
var async = require("async");
var card = require('./channel_card_type');
//var cache = require('redis');

var seatData = {
	//holds:[3,1,2,5,7,12,23,13,10,24,24,16,5],
	//holds:[1,1,1,3,3,3,5,5,5,24,24,24,17,17,17,18],
	//holds:[7,5,6,5,6,7,1,10,9,18,18,18,2],
	//holds:[2,3,4,6,6,6,16,16,20,20,22,23,24],
	//holds:[15,7,31,10,7,6,13,5,4,14,31,7,31],
	//holds:[7,5,6,5,6,7,1,1,1,5,6,28,7],
	//holds:[7,5,6,5,6,7,1,1,1,8],
	//holds:[7,7,1,1],
	//holds:[8],
	//holds:[6,7,8,10,11,12,12,22,23,24],
	//holds:[0,0,7,8,13,14,15],
	//holds:[11,11,11,16],
	//holds:[9,2,2,2,16,10,15],
	//holds:[0,0,0,13,14,15,15,29,29,2],
	//holds:[4,4,15,16,17,19,19,20,21,25],
	//holds:[7,1,1,3,4,5,16,16,22,22],
	//holds:[23,22,3,12,11,21,25,26,13,24],
	//holds:[29,1,2,3,4,13,14,15,19,19,21,22,23],
	//holds:[17,17,18,19,20,31,31],
	//holds:[1,1,1,7],
	//holds:[2,2,2,13,13,20,21,22,23,24],
	//holds:[7,3,3,5,5,12,13,14,23,24,25,26,26],  //3,4,5,26
	//holds:[28,3,3,3,7,7,19,19,19,20,20,21,21,31,31,31],
	//holds:[0,1,2,3,4,5,6,12,13,14],   //0,3,6
	//holds:[22,3,3,3,3,24,24],  								//bug fixed caishen 22  1,2,4,5,22,24
	//holds:[2,4,4,6,6,7,7,10,10,11,11,21,21,22,23,23],  		//bug fixed
	//holds:[0,0,5,6,7,13,14,24,25,26],  						//no bug caishen 22  12,15
	//holds:[13,0,0,2,2,2,4,4,15,16],    					//bug caishen 13 fixed no appear 0,4,14,17
	//holds:[9,2,3,4,5,14,14,14,14,15],  					//no bug caishen 9 2,5,13,16
	//holds:[5,4,4,18,19,20,21,23,24,25],  					//bug  caishen 5 fixed 4,18到23,26
	//holds:[2,3,4,21,22,23,25,25,25,32],					//no bug caishen not sure 32
	//holds:[3,2,2,5,5,12,13,22,23,24],      					//bug fixed caishen 3 2,5,11,14
	//holds:[1,2,6,7,8,19,19],								//bug caishen 28 fixed 0,3
	//holds:[6,7,8,9,10,10,11,11,15,16,17,27,27],  			//bug caishen 19 fixed 9,12
	//holds:[2,3,4,5,6,7,9,10,11,18,18,18,20,21,22,23],       //bug caishen 24 fixed 19,20,23
	//holds:[28,4,24,25,26,26,26],							//bug fixed caishen 28 2,3,4,5,6,23,26
	//holds:[22,22,20,21],						//bug caishen 22 fixed 18,19,20,21,22,23,-1
	//holds:[22,2,2,23,23,23,23],     			//bug caishen 22  fixed 2,21,22,24,25
	//holds:[3,4,5,5,5,11,12,29,15,16,17,19,20,26,26,26],  //bug caishen 13 fixed  18,21
	//holds:[12,6,10,11,29,13,14,15,20,21],   //bug caishen 12 fixed 6,19,22
	//holds:[5,5,2,3,29,6,6,7,7,10,11,12,15,17,31,31],   //bug caishen 5 fixed 1,4,5,8,16
	//holds:[32,1,1,2,2,3,3,7,7,9,10,14,15],   //bug caishen 32 fixed  11,13,16
	//holds:[18,2,2,13,14,14,15,21,22,23],  //bug caishen 18 fixed  2,12,13,14,15,16
	//holds:[25,12,13,14,14,15,16,16,19,20,21,23,23,33,33,33], //caishen 25 no bug   11 13 14 15 16 17 23
	//holds:[9,0,0,11,12,13,14,15,16,18,18,18,19,21,21,22],  //bug caishen 9 漏胡23   20 23
	//holds:[29,0,0,13,14,14,16,17,17,17],  //caishen 29 bug  12 15
	//holds:[0,29,1,2,6,7,9,10,11,13,13,19,20,21,24,25],  //caishen 0  5,8,23,26
	//holds:[33,33,1,2,6,6,10,11,12,22,23,23,25],   //caishen 33 0,3,21,24  bug
	//holds:[8,1,1,19,20,21,23,23,24,24,24,25,26], //caishen 8 bug 1 22 23 24 25  bug 1
	//holds:[9,10,11,11,12,13,15,16,17,20,21,22,23,24,31,31],  // no bug
	//holds:[0,29,1,2,6,7,9,10,11,13,13,19,20,21,24,25],  // no bug
	//holds:[7,7,12,13,18,29,20,21,22,23],  // no bug
	//holds:[3,4,5,6,7,8,10,10,14,15,16,17,17],  // no bug
	//holds:[9,10,11,11,12,13,15,16,17,20,21,22,23,24,31,31], // no bug
	//holds:[1,2,6,7,8,19,19],
	//holds:[6,7,8,9,10,10,11,11,15,16,17,27,27],
	//holds:[0,0,1,1,2,2,2,3,3,4,4,4,5,6,7,7,6],
	//holds:[0,1,2,3,4,10,11,12,12,12,22,23,24,24,25,26],
	//holds:[1,2,29,4,5,6,17,17,22,23,24,25,25],
	//holds:[2,3,4,21,22,23,23,23,24,25],
	//holds:[3,4,5,9,10,11,11,12,14,15,16,29,29,24,25,26],
	//holds:[0,1,2,3,4,24,24],
	//holds:[5,6,7,12,13,14,18,18,19,20,20,21,21,22,22,23],
	//holds:[1,2,3,4,5,9,9,14,15,16,18,25,20,21,22,23,19],
	//holds:[8,8,3,3,4,4,5,5,6,29,13,13,16,16,19,20,21],
	holds: [4, 16, 5, 13, 16, 21, 3, 29, 8, 20, 3, 8, 6, 5, 4, 13, 19],
	holds: [18, 18, 18, 19, 19, 19, 20, 20, 22, 22, 21, 21, 0, 0, 6, 6, 19],
	countMap: {},
	tingMap: {},
	userId: 2,
}
function isTinged(seatData) {
	for (var k in seatData.tingMap) {
		return true;
	}
	return false;
}

for (var i = 0; i < seatData.holds.length; ++i) {
	var pai = seatData.holds[i];
	if (seatData.countMap[pai] == null) {
		seatData.countMap[pai] = 1;
	}
	else {
		seatData.countMap[pai]++;
	}
}
//for (var i=0;i<100;++i)
{
	//hp.checkCanTingPaiByBuPai(seatData,31,29,1);
}
for (var k in seatData.tingMap) {
	console.log("牌值 = " + k);
}

if (isTinged(seatData)) {
	console.log("ting pai ");
}
//console.log(" show end !!!!!!");

/*

//bagpipe
 var async = function(val, callback) {
 	setTimeout(function() {}, 1000);
 }
 var bagpipe = new Bagpipe(500);
 for (var i=0; i<docs.length; i++) {
	bagpipe.push(async, docs[i].value, function(callback) {
 });
 }

 //async
 var q = async.queue(function(task, callback) {
 setTimeout(function() {
 	log.info(task);
 	callback(null, {});}, 5000);}, 10);
 	q.drain = function() {
 	log.info("finish");}
 	for (var i=0; i<100; i++) {
 		q.push(i, function(err, data) {
 	});
 }

//var game = {};
//var roomInfo = {};
//var dbresult = [0,0,0,0];
//var roomId = 1;
//var results = true;
//var userId = 146;
//seriesSaveToDB(game,roomInfo,dbresult,roomId,results,userId);

/*
var cmd=process.platform=='win32'?'tasklist':'ps aux';
var exec = require('child_process').exec;
var qqname='qq';
exec(cmd, function(err, stdout, stderr) 
{
    if(err)
	{ 
		return console.log(err); 
	}
    stdout.split('\n').filter(function(line)
	{
        var p=line.trim().split(/\s+/),pname=p[0],pid=p[1];
        if(pname.toLowerCase().indexOf(qqname)>=0 && parseInt(pid))
		{
            console.log(pname,pid);
        }
    });
});
*/

// var bRes = check8PairsRes(seatData, 21, false);
// console.log(bRes);

// var holdsTmp = [1, 2, 3];
// var rsType = card.calCardType(2, holdsTmp, 3);
// console.log("fffffff ", rsType);

// var client = cache.createClient();
// client.on('ready', function(err){
// 	console.log("ready");
// });

var redis = require('redis'),
    RDS_PORT = 6379,        //端口号
    RDS_HOST = '127.0.1.1',    //服务器IP
    RDS_PWD = 'foobared',    //密码    
    RDS_OPTS = {},            //设置项
    client = redis.createClient(RDS_PORT,RDS_HOST,RDS_OPTS);

client.auth(RDS_PWD,function(){
    console.log('通过认证');
});

// client.on('connect',function(){
//     client.set('author', 'Wilson',redis.print);
//     client.get('author', redis.print);
//     console.log('connect');
// });

// client.on('connect',function(){
//     client.hmset('short', {'js':'javascript','C#':'C Sharp'}, redis.print);
//     client.hmset('short', 'SQL','Structured Query Language','HTML','HyperText Mark-up Language', redis.print);

//     client.hgetall("short", function(err,res){
//         if(err)
//         {
//             console.log('Error:'+ err);
//             return;
//         }            
//         console.dir(res);
//     });
// });

client.on('connect',function(){
    var key = 'skills';
      client.sadd(key, 'C#','java',redis.print);
      client.sadd(key, 'nodejs');
      client.sadd(key, "MySQL");
      
      client.multi()      
      .sismember(key,'C#')
      .smembers(key)
      .exec(function (err, replies) {
            console.log("MULTI got " + replies.length + " replies");
            replies.forEach(function (reply, index) {
                console.log("Reply " + index + ": " + reply.toString());
            });
            client.quit();
    });
});


// client.on('ready',function(err){
//     console.log('ready');
// });

